package com.lys.conf;

import org.apache.zookeeper.ZooKeeper;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

public class ZookeeperUtil {
    private static String nodes = "192.168.127.128:2181,192.168.127.129:2181,192.168.127.130:2181,192.168.127.131:2181/testConfig";

    private static ZooKeeper zooKeeper;

    public static ZooKeeper getZooKeeper(){
        try {
            CountDownLatch countDownLatch = new CountDownLatch(1);
            DefaultWatcher defaultWatcher = new DefaultWatcher();
            defaultWatcher.setCountDownLatch(countDownLatch);
            zooKeeper = new ZooKeeper(nodes, 3000, defaultWatcher);
            countDownLatch.await();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return ZookeeperUtil.zooKeeper;
    }
}
